package com.wiley.appiumConcurrent;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import io.appium.java_client.android.AndroidDriver;

public class Demo {
	private AndroidDriver<WebElement> driver;

	@Test
	@Parameters({ "port", "udid" })
	public void login(String port,String udid) throws MalformedURLException, InterruptedException {
		System.out.println("port is: " + port + ", udid is: " + udid);
		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability("deviceName", "android emulator");
		capabilities.setCapability("udid", udid);
		capabilities.setCapability("appPackage", "com.haodou.recipe");
		capabilities.setCapability("appActivity", "com.haodou.recipe.Main");
		driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:" + port + "/wd/hub"), capabilities);
		Thread.sleep(3000);
		driver.findElement(By.id("com.haodou.recipe:id/mine_item")).click();
	}

	@AfterClass
	public void teardown(){
		driver.quit();
	}
}
